<template>
  
  <div>
    <div>
      <div class="block" >
    
    <el-carousel class="zou" height="400px"  direction="vertical" >
      
      <el-carousel-item v-for="item in avatardata" :key="item.id" >
      <!-- <h3 class="medium">{{ item }}</h3> -->
      
      <img style="width: 100%; height: 100%" :src="'http://localhost:5000/files/'+item.avatar" class="image"
         @click="handleWatch(item)"   /> 
      </el-carousel-item>
    </el-carousel>
  </div>
  
  
  
    </div>
    
    
    
    <!-- <div v-html="this.tableData[4].context"></div> -->
    
  <!-- <News :articleid=articleid></News> -->
  
    <div id="x" style="height:100px" >
      
      <div class="side">
        
       <el-card class="aide_card">
         
              <div slot="header" class="clearfix">
                <span>阅读排行榜</span>
                <!-- <el-button style="float: right; padding: 3px 0" type="text"
                  >更多>></el-button -->
              </div>

              <div v-for="(item, id) of Numtable" :key="id">
      <div>
            
            <el-col :span="15">
              
              <el-button type="text" class="button" @click="handleWatch(item)">
              <font class="s" >{{ item.title }} </font>  
              <br>
              <div class="w" ><i  style="font-size:15px" class="el-icon-s-order" >{{ item.numReadings }}</i> </div>
              </el-button>
              
            </el-col>
            
             
        

       
      </div>
    </div>
            </el-card>

            <!-- <el-carousel
              indicator-position="outside"
              style="width: 380px"
              height="200px"
            >
              <el-carousel-item v-for="item in images" :key="item.index">
                <img :src="item.url" alt="无图片" />
              </el-carousel-item>
            </el-carousel> -->
             <el-card class="aide_card">
         
              <div slot="header" class="clearfix">
                <span>点赞排行榜</span>
                <!-- <el-button style="float: right; padding: 3px 0" type="text"
                  >更多>></el-button -->
              </div>

              <div v-for="(item, id) of Liketable" :key="id">
      <div>
            
            <el-col :span="15">
              
              <el-button type="text" class="button" @click="handleWatch(item)">
              <font class="s" >{{ item.title }} </font>  
              <br>
              <div class="w" ><i  style="font-size:15px" class="el-icon-star-on" >{{ item.likes }}</i> </div>
              </el-button>
              
            </el-col>
            
             
        

       
      </div>
    </div>
            </el-card>


            
              <el-card class="Code">
          <div class="QRCode1">
            <div class="FooterText1">
              
              <p>扫描关注公众号</p>
            </div>
          </div>

          <div class="QRCode1">
            <div class="FooterText1">
              <p>扫描添加微信群</p>
            </div>
          </div>

          <div class="QRCode1">
            <div class="FooterText1">
              <p>扫描添加QQ群</p>
            </div>
          </div>

          <div class="FooterText2">
            Copyright © APE科技版权所有.
            <br>  
            公安备案号：<a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=35062702000151">
        <p><img src="../views/imgs/备案图标 (1).png" style="width:15px"> 闽公安备案号35062702000151</p>
        </a>
        
            <br>
            域名备案号：<a href="http://beian.miit.gov.cn/">
            <p>闽ICP备2020020549号</p>
            </a>
          </div>
        </el-card>


            <!-- <el-carousel
              indicator-position="outside"
              style="width: 380px"
              height="200px"
            >
              <el-carousel-item v-for="item in images" :key="item.index">
                <img :src="item.url" alt="无图片" />
              </el-carousel-item>
            </el-carousel> -->
    </div>
    
    </div>
    
    <el-form>
      
    </el-form>

    <div v-for="(item, id) of tableData" :key="id" class="main"  @click="handleWatch(item)">
      
        <el-card class="card">
          
          <el-row :gutter="10">
            <el-col :span="3"
              ><img :src="'http://localhost:5000/files/'+item.avatar" class="image"
            /></el-col>
            <el-col :span="21">
              <el-button type="text" class="button">
                 <div class="o" v-html="item.title"></div> 
              </el-button>
              <div  class="p" v-html="item.context"></div>
              <div class="other">
                
                
              </div></el-col
            >
          </el-row>
          
        </el-card>
        

       
      

    </div>
    
    
    



    
  </div>
</template>

<script>

import { getList, addarticles, getById ,deleteId,numReadings,latest,Likes } from "../api/articles";
import { getarictlesList } from "../api/articlecomments";

// import News1 from './news1.vue';
// import News from './news.vue';
export default {
  // components: { News },
  data() {
    return {
      avatardata:{
        avatar:""
      },
      Numtable:'',
      Liketable:'',
      form:{
        title:'',
        numReadings:''
      },
      form1:{
        title:'',
        likes:''
      },
      commentData: {
        id: "",
        comment: "",
      },
      editor: null,
      id:'',
      editorData: "",
      tableData: [],
      commentaa: [],
      article: {
        title: "",
        context: "",
      },
       Data:{
        title:'',
        context:''
      },
      formData: {
        title: "",
        context: "",
        author: "",
        avatar:""
      },
      dialogFormVisible: false,
      dialogVisible: false,
      imageUrl: "",
      dialogFormAvatarFullUrl:''
    };
  },
  
  computed:{
    uploadActionUrl(){
      let baseUrl='http://localhost:5000/'
      let url='files/uploadfiles'
      return baseUrl + url
    },
    articleid(){
      var id=this.id;
      return id
    }
    
  
  },
  methods: {
    handleAvatarSuccess(res, file) {
      this.formData.avatar = URL.createObjectURL(file.raw);
      // 保存相对路径
      let prePath=res.data[0];
      // 显示使用完整路径
      let fullPath=URL.createObjectURL(file.raw);
      this.formData.avatar = prePath
      this.dialogFormAvatarFullUrl=fullPath
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    },
    handleAdd() {
      this.dialogFormVisible = true;
      this.formData.name = "";
      this.formData.context = "";
      this.formData.author = "";
    },
    handleWatch(item) {
      this.dialogVisible = true;
      this.id=item.id;
      console.log(this.id);

      console.log(this.tableData);
      console.log(item);
      this.Data.title = item.title;
      this.Data.context = item.context;
      getarictlesList(item.id).then((res) => {
        // console.log(res.data.data);
        this.commentData = res.data.data;
        this.commentData.forEach((element) => {
          getById(element.commentId).then((res) => {
            this.commentaa.push(res.data.data);
          });
        });
      });
      this.commentaa = [];
      this.$router.push("/news?id="+item.id);


      
      
    },
    handleClick(row) {
      console.log(row);
    },
deleted(row) {
      console.log(row);
      this.currentIndex = row;
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          deleteId(row)
            .then((res) => {
              console.log(res);
              if (res.code === 1000) {
                this.tableData.splice(row.id, 1);
              }
            })
            .catch((err) => {
              console.log(err);
            });
          this.fetchData(this.article);
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    
     getEditorData() {
      this.dialogFormVisible = false;
      var data = this.editor.txt.html();
      console.log(data);
      this.formData.context = data;
      this.tableData.push(data);
      //添加到数据库并且返回数据
      console.log(this.formData);
      addarticles(this.formData).then((res) => {
        console.log(res);
        console.log();
      });
      this.fetchData(this.article);
    }, fetchData() {
      getList(this.article)
        .then(({ data }) => {
          var res = data.data.data;
          console.log(res);
          this.tableData = res;
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
  mounted() {
    this.fetchData(this.article);
    numReadings(this.form).then(({data})=>{
      var res=data.data.data;
      console.log(res);
      this.Numtable=res;
      console.log(this.Numtable);

    }).catch(err=>{
      console.log(err);
    });
    Likes(this.form1).then(({data})=>{
      var res=data.data.data;
      console.log(res);
      this.Liketable=res;
      console.log(this.Numtable);

    }).catch(err=>{
      console.log(err);
    });
    latest(this.avatardata).then(({data})=>{
      var res=data.data.data
      console.log(res);
      this.avatardata=res;
      console.log(this.avatardata);
    }).catch(err=>{
      console.log(err);
    })

   
    
    
  },
};
</script>

<style>
body{
  background-color:#EAEAEF  ;
    display: flex;
    flex-direction: row;
    justify-content: center;
    
  width:auto

}
.p{
  
   width: 300px;
   text-overflow: ellipsis;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp:1;
overflow: hidden;
white-space:pre-wrap;
}
.s{
  font-family:'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
  font-size: 20px;
  color:#409eff;
  font-style: oblique;
}
.clearfix{
  font-size: 15px;
  font-style: oblique;
  background-color: antiquewhite;
}
.o{
   font-size: 22px;
   color:cadetblue;
   width: 500px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display:block;
}
.w{
  float: left; 
   
}

/* .block{
  display: flex;
align-items: center;
justify-content: center;
} */
.el-col-21{
width: 100px;
margin-left: 65px;
}

.main{
 width: 1400px;
  /* float: left; */
  /* float:1px 1px; */

}

.side{
  float: right;
  /* height:100%; */
  width: 250px;
  text-align: left;

}


.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 120px;
  height: 120px;
  line-height: 120px;
  /* text-align: center; */
}
.avatar {
  width: 120px;
  height: 120px;
  display: block;
}
.card {
  height: 160px;
  background: white;
  margin-top: 5px;
  width: 700px;
  float: left;
  margin: 20px 220px;
  /* text-overflow: ellipsis; */
  
 
}

.button {
  font-size: 28px;
  color: black;
}

.image {
  width: 120px;
  height: 120px;
}

.intro {
  height: 40px;
}

.other {
  text-align: right;
}
.Code {
  width: 260px;
  height: 1200px;
}
.QRCode1 {
  width: 250px;
  height: 300px;
  padding: -60px;
  background-color: white;
  float: left;
  background-image: url("../views/imgs/Code4.jpg") !important;
  background-repeat: no-repeat;
}

.FooterText1 {
  margin-left: 40px;
  margin-top: 200px;
  color: #409eff;
}
.FooterText2{
  margin-top: -10px;
  font-size: 12px;
}
</style>